package com.graduation.smartparkingplatform.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.graduation.smartparkingplatform.Dao.ChargeMapper;
import com.graduation.smartparkingplatform.Pojo.Charge;
import com.graduation.smartparkingplatform.Service.ChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ChargeServiceImpl implements ChargeService {

  @Autowired ChargeMapper chargeMapper;

  // 获取Charge列表（分页）
  @Override
  public PageInfo<Charge> getChargeList(Integer page, Integer count) {
    PageHelper.startPage(page, count);

    List<Charge> chargeList = chargeMapper.getChargeList();

    PageInfo<Charge> pageInfo = new PageInfo<>(chargeList);

    return pageInfo;
  }

  // 模糊搜索Region（分页）
  @Override
  public PageInfo<Charge> searchCharge(
      Integer page, Integer count, String chargeType, String chargeName) {
    PageHelper.startPage(page, count);

    List<Charge> searchList = chargeMapper.searchCharge(chargeType, chargeName);

    PageInfo<Charge> pageInfo = new PageInfo<>(searchList);

    return pageInfo;
  }

  // 添加计费规则
  @Override
  public Boolean addCharge(Charge charge) {
    Boolean chargeType = charge.getCharge_type();
    String chargeName = charge.getCharge_name();
    Integer chargeFreeTime = charge.getCharge_free_time();
    BigDecimal chargeMin = charge.getCharge_charging_min();
    BigDecimal chargeMax = charge.getCharge_max();
    BigDecimal chargeUnitt = charge.getCharge_unitt();
    BigDecimal chargeChargingMin = charge.getCharge_charging_min();
    BigDecimal chargeChargingUnitt = charge.getCharge_charging_unitt();
    String remarks = charge.getRemarks();
    return chargeMapper.addCharge(
        chargeType,
        chargeName,
        chargeFreeTime,
        chargeMin,
        chargeMax,
        chargeUnitt,
        chargeChargingMin,
        chargeChargingUnitt,
        remarks);
  }

  // 修改计费规则信息
  @Override
  public Boolean chargeInfo(Charge charge) {
    Integer chargeId = charge.getCharge_id();
    Boolean chargeType = charge.getCharge_type();
    String chargeName = charge.getCharge_name();
    Integer chargeFreeTime = charge.getCharge_free_time();
    BigDecimal chargeMin = charge.getCharge_charging_min();
    BigDecimal chargeMax = charge.getCharge_max();
    BigDecimal chargeUnitt = charge.getCharge_unitt();
    BigDecimal chargeChargingMin = charge.getCharge_charging_min();
    BigDecimal chargeChargingUnitt = charge.getCharge_charging_unitt();
    String remarks = charge.getRemarks();

    return chargeMapper.chargeInfo(
        chargeId,
        chargeType,
        chargeName,
        chargeFreeTime,
        chargeMin,
        chargeMax,
        chargeUnitt,
        chargeChargingMin,
        chargeChargingUnitt,
        remarks);
  }

  // 删除计费规则
  @Override
  public Boolean deleteCharge(Integer chargeId) {
    return chargeMapper.deleteCharge(chargeId);
  }
}
